﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;

namespace WPSPU_Day2
{
    public partial class TakePhotoPage : PhoneApplicationPage
    {
        public TakePhotoPage()
        {
            InitializeComponent();
        }

        private void openCamera_Click(object sender, System.EventArgs e)
        {
        	//PhotoChooserTask photo = new PhotoChooserTask();
			CameraCaptureTask camera = new CameraCaptureTask();
			camera.Completed += new System.EventHandler<Microsoft.Phone.Tasks.PhotoResult>(camera_Completed);
			camera.Show();
        }

        private void camera_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e)
        {
        	if(e.TaskResult == TaskResult.OK){
				myphoto.Source = new BitmapImage(new Uri(e.OriginalFileName,
					UriKind.Absolute));
			}
        }

        private void browsePhoto_Click(object sender, System.EventArgs e)
        {
        	PhotoChooserTask photo = new PhotoChooserTask();
			photo.Completed +=new System.EventHandler<Microsoft.Phone.Tasks.PhotoResult>(photo_Completed);
			photo.ShowCamera = true;
			photo.Show(); 
			
        }

        private void photo_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e)
        {
        	if(e.TaskResult == TaskResult.OK){
				myphoto.Source = new BitmapImage(new Uri(e.OriginalFileName,
					UriKind.Absolute));
			}
			
        }
    }
}
